<?php
/**
 *
 * 功能描述（商品数据）
 *
 * @author suoya <jlusuoya@gmail.com>
 * @version 1
 */

class ModelFood extends ModelBase
{
	function GetGoodsList($page, $where)
	{
		$where .= " and visible = 1";
		$data  = $this->db->getRow("goods_base", 'count(1) cnt', $where);
		if($data['cnt'] == 0)
			return array('cnt' => 0, 'pageCnt' => 0, 'data' => array());

		$goods = array('cnt' => $data['cnt'], 'pageCnt' => ceil($data['cnt'] / GOODS_PAGESIZE));
		$limit = GOODS_PAGESIZE * ($page - 1) . ", " . GOODS_PAGESIZE;
		$data = $this->db->getAll("goods_base", "id, name, `type`, `type2`, `discount`,  introduce, price , unit", $where, 'sales desc, id desc', $limit);
		foreach($data as $k => $item)
			$data[$k]['introduce'] = explode("\n", $item['introduce']);
		$goods['data'] = $data;
		return $goods;
	}

	function GetGoods($id)
	{
		$data  = $this->db->getRow("goods_base", 'id, version, updatetime, name, introduce, discount', "visible = 1 and id = $id");
		if($data === false)
			return false;
		$data['introduce'] = explode("\n", $data['introduce']);
		return $data;
	}

	function GetPrice($where)
	{
		$data = $this->db->getAll("goods_price", "id, size, `describe`, price, unit, `default` ", $where);
		return $data;
	}

	function GetInfo($id)
	{
		$filds = "`taste`, `suits`, `sweetness`, `storage`, `holiday`, `material`, `attr1`, `attr2`, `attr3`, `attr4`, `attr5`";
		$data = $this->db->getRow("goods_info", $filds, "goods_id = $id");
		return $data;
	}
}

